outcome_acquitted_not_asoc=mean(outcome_abc[acquitted==1&asoc_illicit_crime==0], na.rm=T),
outcome_convicted_not_asoc=mean(outcome_abc[acquitted==0&asoc_illicit_crime==0], na.rm=T),
num=n(),
age=mean(age, na.rm=T),
students=mean(student, na.rm=T),
basque_region=mean(basque_region, na.rm=T),
basque_terms=mean(basque_terms, na.rm=T),
acquitted=mean(acquitted, na.rm=T),
fiscal_log=mean(fiscal_log, na.rm=T),
fiscal=mean(fiscal, na.rm=T),
punishment=mean(punishment, na.rm=T),
protest_terms=mean(protest_terms, na.rm=T),
protest_crime=mean(protest_crime, na.rm=T),
propaganda_crime=mean(propaganda_crime, na.rm=T),
communism_terms=mean(communism_terms, na.rm=T),
state_security_crimes=mean(state_security_crimes, na.rm=T),
armas_terms=mean(armas_terms, na.rm=T),
arms_crime=mean(arms_crime, na.rm=T),
agreed=mean(agreed, na.rm=T),
asoc_illicit_crime=mean(asoc_illicit_crime, na.rm=T),
public_disorder_crime=mean(public_disorder_crime, na.rm=T),
proposed_punishment=mean(proposed_punishment, na.rm=T),
dictatorship_terms=mean(dictatorship_terms, na.rm=T),
subversion_terms=mean(subversion_terms, na.rm=T),
preventiva=mean(preventiva, na.rm=T),
recommended_acquit=mean(recommended_acquit, na.rm=T),
prison_time=mean(prison_time, na.rm=T),
dictatorship_terms=mean(dictatorship_terms, na.rm=T),
buena=mean(buena, na.rm=T),
disagreement=mean(disagreement, na.rm=T),
num_crimes=mean(num_crimes, na.rm=T),
num_defendants=mean(num_defendants, na.rm=T),
punishment_pris=mean(punishment_pris, na.rm=T),
defense_guilty=mean(defense_guilty, na.rm=T),
defense_nocrime=mean(defense_nocrime, na.rm=T),
defense_denies=mean(defense_denies, na.rm=T),
defense_attenuate=mean(defense_attenuate, na.rm=T),
any_punishment=mean(any_punishment, na.rm=T),
length_of_detention=mean(length_of_detention, na.rm=T),
num_abc_mentions=sum(abc_has_info, na.rm=T),
outcome_abc=mean(outcome_abc, na.rm=T),
abc_has_info=mean(abc_has_info, na.rm=T),
case_abc=mean(case_abc, na.rm=T),
num_pt_detention_mentions=sum(pretrial_detention_abc, na.rm=T),
num_pt_release_mentions=sum(pretrial_release_abc, na.rm=T),
pretrial_detention_abc=mean(pretrial_detention_abc, na.rm=T),
pretrial_release_abc=mean(pretrial_release_abc, na.rm=T),
pc_unproven=mean(unproven, na.rm=T)
)%>%
filter(date>'1964-01-01'))
ggplot(summary_data_st, aes(x=date, y=articles_by_paper))+
geom_line()+geom_vline(xintercept=as.Date('1967-03-15'))
ggplot() +
geom_line(data = summary_data_st, aes(x = date, y = acquitted_abc, linetype = "As Reported")) +
geom_line(data = summary_data_st, aes(x = date, y = acquitted, linetype = "Overall")) +
geom_vline(xintercept = as.Date('1970-01-01'), color = 'grey', linetype = 'dotted') +
scale_linetype_manual(values = c("As Reported" = "dashed", "Overall" = "solid")) +
labs(linetype = "Acquitted")  +xlab('Year')+ ylab('Proportion of Acquittals')+
ggtitle('Acquittals - real versus reported')
ggplot() +
geom_line(data = summary_data_st, aes(x = date, y = acquitted_abc, linetype = "As Reported")) +
geom_line(data = summary_data_st, aes(x = date, y = acquitted, linetype = "Overall")) +
geom_vline(xintercept = as.Date('1970-12-01'), color = 'grey', linetype = 'dotted') +
scale_linetype_manual(values = c("As Reported" = "dashed", "Overall" = "solid")) +
labs(linetype = "Acquitted")  +xlab('Year')+ ylab('Proportion of Acquittals')+
ggtitle('Acquittals - real versus reported')
ggplot() +
geom_line(data = summary_data_st, aes(x = date, y = acquitted_abc, linetype = "As Reported")) +
geom_line(data = summary_data_st, aes(x = date, y = acquitted, linetype = "Overall")) +
geom_vline(xintercept = as.Date('1970-06-01'), color = 'grey', linetype = 'dotted') +
scale_linetype_manual(values = c("As Reported" = "dashed", "Overall" = "solid")) +
labs(linetype = "Acquitted")  +xlab('Year')+ ylab('Proportion of Acquittals')+
ggtitle('Acquittals - real versus reported')
## summarize the data
summary_data_st<-data.frame(top_data %>%
group_by(date=floor_date(trialDate, '6 months')) %>%
dplyr::summarize(
articles_by_paper=length(min_abc_date[is.na(min_abc_date)==F]),
acquitted_abc=mean(acquitted[outcome_abc==1], na.rm=T),
punishment_abc=mean(punishment[outcome_abc==1], na.rm=T),
outcome_acquitted=mean(outcome_abc[acquitted==1], na.rm=T),
outcome_convicted=mean(outcome_abc[acquitted==0], na.rm=T),
outcome_acquitted_asoc=mean(outcome_abc[acquitted==1&asoc_illicit_crime==1], na.rm=T),
outcome_convicted_asoc=mean(outcome_abc[acquitted==0&asoc_illicit_crime==1], na.rm=T),
outcome_acquitted_not_asoc=mean(outcome_abc[acquitted==1&asoc_illicit_crime==0], na.rm=T),
outcome_convicted_not_asoc=mean(outcome_abc[acquitted==0&asoc_illicit_crime==0], na.rm=T),
num=n(),
age=mean(age, na.rm=T),
students=mean(student, na.rm=T),
basque_region=mean(basque_region, na.rm=T),
basque_terms=mean(basque_terms, na.rm=T),
acquitted=mean(acquitted, na.rm=T),
fiscal_log=mean(fiscal_log, na.rm=T),
fiscal=mean(fiscal, na.rm=T),
punishment=mean(punishment, na.rm=T),
protest_terms=mean(protest_terms, na.rm=T),
protest_crime=mean(protest_crime, na.rm=T),
propaganda_crime=mean(propaganda_crime, na.rm=T),
communism_terms=mean(communism_terms, na.rm=T),
state_security_crimes=mean(state_security_crimes, na.rm=T),
armas_terms=mean(armas_terms, na.rm=T),
arms_crime=mean(arms_crime, na.rm=T),
agreed=mean(agreed, na.rm=T),
asoc_illicit_crime=mean(asoc_illicit_crime, na.rm=T),
public_disorder_crime=mean(public_disorder_crime, na.rm=T),
proposed_punishment=mean(proposed_punishment, na.rm=T),
dictatorship_terms=mean(dictatorship_terms, na.rm=T),
subversion_terms=mean(subversion_terms, na.rm=T),
preventiva=mean(preventiva, na.rm=T),
recommended_acquit=mean(recommended_acquit, na.rm=T),
prison_time=mean(prison_time, na.rm=T),
dictatorship_terms=mean(dictatorship_terms, na.rm=T),
buena=mean(buena, na.rm=T),
disagreement=mean(disagreement, na.rm=T),
num_crimes=mean(num_crimes, na.rm=T),
num_defendants=mean(num_defendants, na.rm=T),
punishment_pris=mean(punishment_pris, na.rm=T),
defense_guilty=mean(defense_guilty, na.rm=T),
defense_nocrime=mean(defense_nocrime, na.rm=T),
defense_denies=mean(defense_denies, na.rm=T),
defense_attenuate=mean(defense_attenuate, na.rm=T),
any_punishment=mean(any_punishment, na.rm=T),
length_of_detention=mean(length_of_detention, na.rm=T),
num_abc_mentions=sum(abc_has_info, na.rm=T),
outcome_abc=mean(outcome_abc, na.rm=T),
abc_has_info=mean(abc_has_info, na.rm=T),
case_abc=mean(case_abc, na.rm=T),
num_pt_detention_mentions=sum(pretrial_detention_abc, na.rm=T),
num_pt_release_mentions=sum(pretrial_release_abc, na.rm=T),
pretrial_detention_abc=mean(pretrial_detention_abc, na.rm=T),
pretrial_release_abc=mean(pretrial_release_abc, na.rm=T),
pc_unproven=mean(unproven, na.rm=T)
)%>%
filter(date>'1964-01-01'))
ggplot() +
geom_line(data = summary_data_st, aes(x = date, y = acquitted_abc, linetype = "As Reported")) +
geom_line(data = summary_data_st, aes(x = date, y = acquitted, linetype = "Overall")) +
geom_vline(xintercept = as.Date('1970-06-01'), color = 'grey', linetype = 'dotted') +
scale_linetype_manual(values = c("As Reported" = "dashed", "Overall" = "solid")) +
labs(linetype = "Acquitted")  +xlab('Year')+ ylab('Proportion of Acquittals')+
ggtitle('Acquittals - real versus reported')
## summarize the data
summary_data_st<-data.frame(top_data %>%
group_by(date=floor_date(trialDate, '1 year')) %>%
dplyr::summarize(
articles_by_paper=length(min_abc_date[is.na(min_abc_date)==F]),
acquitted_abc=mean(acquitted[outcome_abc==1], na.rm=T),
punishment_abc=mean(punishment[outcome_abc==1], na.rm=T),
outcome_acquitted=mean(outcome_abc[acquitted==1], na.rm=T),
outcome_convicted=mean(outcome_abc[acquitted==0], na.rm=T),
outcome_acquitted_asoc=mean(outcome_abc[acquitted==1&asoc_illicit_crime==1], na.rm=T),
outcome_convicted_asoc=mean(outcome_abc[acquitted==0&asoc_illicit_crime==1], na.rm=T),
outcome_acquitted_not_asoc=mean(outcome_abc[acquitted==1&asoc_illicit_crime==0], na.rm=T),
outcome_convicted_not_asoc=mean(outcome_abc[acquitted==0&asoc_illicit_crime==0], na.rm=T),
num=n(),
age=mean(age, na.rm=T),
students=mean(student, na.rm=T),
basque_region=mean(basque_region, na.rm=T),
basque_terms=mean(basque_terms, na.rm=T),
acquitted=mean(acquitted, na.rm=T),
fiscal_log=mean(fiscal_log, na.rm=T),
fiscal=mean(fiscal, na.rm=T),
punishment=mean(punishment, na.rm=T),
protest_terms=mean(protest_terms, na.rm=T),
protest_crime=mean(protest_crime, na.rm=T),
propaganda_crime=mean(propaganda_crime, na.rm=T),
communism_terms=mean(communism_terms, na.rm=T),
state_security_crimes=mean(state_security_crimes, na.rm=T),
armas_terms=mean(armas_terms, na.rm=T),
arms_crime=mean(arms_crime, na.rm=T),
agreed=mean(agreed, na.rm=T),
asoc_illicit_crime=mean(asoc_illicit_crime, na.rm=T),
public_disorder_crime=mean(public_disorder_crime, na.rm=T),
proposed_punishment=mean(proposed_punishment, na.rm=T),
dictatorship_terms=mean(dictatorship_terms, na.rm=T),
subversion_terms=mean(subversion_terms, na.rm=T),
preventiva=mean(preventiva, na.rm=T),
recommended_acquit=mean(recommended_acquit, na.rm=T),
prison_time=mean(prison_time, na.rm=T),
dictatorship_terms=mean(dictatorship_terms, na.rm=T),
buena=mean(buena, na.rm=T),
disagreement=mean(disagreement, na.rm=T),
num_crimes=mean(num_crimes, na.rm=T),
num_defendants=mean(num_defendants, na.rm=T),
punishment_pris=mean(punishment_pris, na.rm=T),
defense_guilty=mean(defense_guilty, na.rm=T),
defense_nocrime=mean(defense_nocrime, na.rm=T),
defense_denies=mean(defense_denies, na.rm=T),
defense_attenuate=mean(defense_attenuate, na.rm=T),
any_punishment=mean(any_punishment, na.rm=T),
length_of_detention=mean(length_of_detention, na.rm=T),
num_abc_mentions=sum(abc_has_info, na.rm=T),
outcome_abc=mean(outcome_abc, na.rm=T),
abc_has_info=mean(abc_has_info, na.rm=T),
case_abc=mean(case_abc, na.rm=T),
num_pt_detention_mentions=sum(pretrial_detention_abc, na.rm=T),
num_pt_release_mentions=sum(pretrial_release_abc, na.rm=T),
pretrial_detention_abc=mean(pretrial_detention_abc, na.rm=T),
pretrial_release_abc=mean(pretrial_release_abc, na.rm=T),
pc_unproven=mean(unproven, na.rm=T)
)%>%
filter(date>'1964-01-01'))
ggplot() +
geom_line(data = summary_data_st, aes(x = date, y = acquitted_abc, linetype = "As Reported")) +
geom_line(data = summary_data_st, aes(x = date, y = acquitted, linetype = "Overall")) +
geom_vline(xintercept = as.Date('1970-06-01'), color = 'grey', linetype = 'dotted') +
scale_linetype_manual(values = c("As Reported" = "dashed", "Overall" = "solid")) +
labs(linetype = "Acquitted")  +xlab('Year')+ ylab('Proportion of Acquittals')+
ggtitle('Acquittals - real versus reported')
ggsave('acquitted_overallvreported.pdf', width=5, height=4)
ggplot() +
geom_line(data = summary_data_st, aes(x = date, y = acquitted_abc, linetype = "As Reported")) +
geom_line(data = summary_data_st, aes(x = date, y = acquitted, linetype = "Overall")) +
geom_vline(xintercept = as.Date('1970-01-01'), color = 'grey', linetype = 'dotted') +
scale_linetype_manual(values = c("As Reported" = "dashed", "Overall" = "solid")) +
labs(linetype = "Acquitted")  +xlab('Year')+ ylab('Proportion of Acquittals')+
ggtitle('Acquittals - real versus reported')
ggsave('acquitted_overallvreported.pdf', width=5, height=4)
ggplot(summary_data_st, aes(x=date, y=articles_by_paper))+
geom_line()
top_data$paper_date[top_data$filename=='51_68']
top_data$min_abc_date[top_data$filename=='51_68']
## summarize the data
summary_data_st<-data.frame(top_data %>%
group_by(date=floor_date(trialDate, '1 year')) %>%
dplyr::summarize(
articles_by_paper=length(max_abc_date[is.na(min_abc_date)==F]),
acquitted_abc=mean(acquitted[outcome_abc==1], na.rm=T),
punishment_abc=mean(punishment[outcome_abc==1], na.rm=T),
outcome_acquitted=mean(outcome_abc[acquitted==1], na.rm=T),
outcome_convicted=mean(outcome_abc[acquitted==0], na.rm=T),
outcome_acquitted_asoc=mean(outcome_abc[acquitted==1&asoc_illicit_crime==1], na.rm=T),
outcome_convicted_asoc=mean(outcome_abc[acquitted==0&asoc_illicit_crime==1], na.rm=T),
outcome_acquitted_not_asoc=mean(outcome_abc[acquitted==1&asoc_illicit_crime==0], na.rm=T),
outcome_convicted_not_asoc=mean(outcome_abc[acquitted==0&asoc_illicit_crime==0], na.rm=T),
num=n(),
age=mean(age, na.rm=T),
students=mean(student, na.rm=T),
basque_region=mean(basque_region, na.rm=T),
basque_terms=mean(basque_terms, na.rm=T),
acquitted=mean(acquitted, na.rm=T),
fiscal_log=mean(fiscal_log, na.rm=T),
fiscal=mean(fiscal, na.rm=T),
punishment=mean(punishment, na.rm=T),
protest_terms=mean(protest_terms, na.rm=T),
protest_crime=mean(protest_crime, na.rm=T),
propaganda_crime=mean(propaganda_crime, na.rm=T),
communism_terms=mean(communism_terms, na.rm=T),
state_security_crimes=mean(state_security_crimes, na.rm=T),
armas_terms=mean(armas_terms, na.rm=T),
arms_crime=mean(arms_crime, na.rm=T),
agreed=mean(agreed, na.rm=T),
asoc_illicit_crime=mean(asoc_illicit_crime, na.rm=T),
public_disorder_crime=mean(public_disorder_crime, na.rm=T),
proposed_punishment=mean(proposed_punishment, na.rm=T),
dictatorship_terms=mean(dictatorship_terms, na.rm=T),
subversion_terms=mean(subversion_terms, na.rm=T),
preventiva=mean(preventiva, na.rm=T),
recommended_acquit=mean(recommended_acquit, na.rm=T),
prison_time=mean(prison_time, na.rm=T),
dictatorship_terms=mean(dictatorship_terms, na.rm=T),
buena=mean(buena, na.rm=T),
disagreement=mean(disagreement, na.rm=T),
num_crimes=mean(num_crimes, na.rm=T),
num_defendants=mean(num_defendants, na.rm=T),
punishment_pris=mean(punishment_pris, na.rm=T),
defense_guilty=mean(defense_guilty, na.rm=T),
defense_nocrime=mean(defense_nocrime, na.rm=T),
defense_denies=mean(defense_denies, na.rm=T),
defense_attenuate=mean(defense_attenuate, na.rm=T),
any_punishment=mean(any_punishment, na.rm=T),
length_of_detention=mean(length_of_detention, na.rm=T),
num_abc_mentions=sum(abc_has_info, na.rm=T),
outcome_abc=mean(outcome_abc, na.rm=T),
abc_has_info=mean(abc_has_info, na.rm=T),
case_abc=mean(case_abc, na.rm=T),
num_pt_detention_mentions=sum(pretrial_detention_abc, na.rm=T),
num_pt_release_mentions=sum(pretrial_release_abc, na.rm=T),
pretrial_detention_abc=mean(pretrial_detention_abc, na.rm=T),
pretrial_release_abc=mean(pretrial_release_abc, na.rm=T),
pc_unproven=mean(unproven, na.rm=T)
)%>%
filter(date>'1964-01-01'))
ggplot(summary_data_st, aes(x=date, y=articles_by_paper))+
geom_line()
ggplot() +
geom_line(data = summary_data_st, aes(x = date, y = acquitted_abc, linetype = "As Reported")) +
geom_line(data = summary_data_st, aes(x = date, y = acquitted, linetype = "Overall")) +
geom_vline(xintercept = as.Date('1970-01-01'), color = 'grey', linetype = 'dotted') +
scale_linetype_manual(values = c("As Reported" = "dashed", "Overall" = "solid")) +
labs(linetype = "Acquitted")  +xlab('Year')+ ylab('Proportion of Acquittals')+
ggtitle('Acquittals - real versus reported')
ggplot() +
geom_line(data = summary_data_st, aes(x = date, y = punishment_abc, linetype = "As Reported")) +
geom_line(data = summary_data_st, aes(x = date, y = punishment, linetype = "Overall")) +
geom_vline(xintercept = as.Date('1970-01-01'), color = 'grey', linetype = 'dotted') +
scale_linetype_manual(values = c("As Reported" = "dashed", "Overall" = "solid")) +
labs(linetype = "Punishment") +xlab('Year')+ ylab('Average Punishment (Years)') +
ggtitle('Punishments - real versus reported')
ggplot() +
geom_line(data = summary_data_st, aes(x = date, y = outcome_acquitted, linetype = "Acquitted")) +
geom_line(data = summary_data_st, aes(x = date, y = outcome_convicted, linetype = "Convicted")) +
geom_vline(xintercept = as.Date('1970-01-01'), color = 'grey', linetype = 'dotted') +
scale_linetype_manual(values = c("Acquitted" = "dashed", "Convicted" = "solid")) +
labs(linetype = "Decision") +xlab('Year')+ ylab('Outcome Reported in Press')+
ggtitle('Decisions reported in press')
ggplot() +
geom_line(data = summary_data_st, aes(x = date, y = outcome_acquitted_asoc, linetype = "Acquitted")) +
geom_line(data = summary_data_st, aes(x = date, y = outcome_convicted_asoc, linetype = "Convicted")) +
geom_vline(xintercept = as.Date('1970-01-01'), color = 'grey', linetype = 'dotted') +
scale_linetype_manual(values = c("Acquitted" = "dashed", "Convicted" = "solid")) +
labs(linetype = "Decision") +xlab('Year')+ ylab('Outcome Reported in Press')+
ggtitle('Decisions reported in press - illicit association crimes')
ggplot() +
geom_line(data = summary_data_st, aes(x = date, y = outcome_acquitted_not_asoc, linetype = "Acquitted")) +
geom_line(data = summary_data_st, aes(x = date, y = outcome_convicted_not_asoc, linetype = "Convicted")) +
geom_vline(xintercept = as.Date('1970-01-01'), color = 'grey', linetype = 'dotted') +
scale_linetype_manual(values = c("Acquitted" = "dashed", "Convicted" = "solid")) + ggtitle('Other Crimes')+
labs(linetype = "Decision") +xlab('Year')+ ylab('Outcome Reported in Press')+
ggtitle('Decisions reported in press - other crimes')
plot_data<-ttest_result_fun(top_data, 'abc_has_info',
c('asoc_illicit_crime',
'propaganda_crime',
'protest_crime',
'arms_crime',
'state_security_crimes'))
ggplot(plot_data, aes(x = variable, y = mean*100)) +
geom_pointrange(aes(ymin = ci_lower*100, ymax = ci_upper*100), position = position_dodge(width = 0.3)) +
theme_minimal()+
xlab('')+
ylab("% Reported On")+coord_flip()
feols(outcome_abc~asoc_illicit_crime*acquitted*I(trialDate>=as.Date('1970-12-01'))+num_defendants|trial_year+vecindadProvincial, data=top_data, cluster=~filename)
feols(outcome_abc~acquitted*I(trialDate>=as.Date('1970-12-01'))+num_defendants|trial_year+vecindadProvincial, data=top_data, cluster=~filename)
feols(outcome_abc~I(punishment<=.5)*I(trialDate>=as.Date('1970-12-01'))+num_defendants|trial_year+vecindadProvincial, data=top_data, cluster=~filename)
feols(outcome_abc~asoc_illicit_crime*I(punishment<=.5)*I(trialDate>=as.Date('1970-12-01'))+num_defendants|trial_year+vecindadProvincial, data=top_data, cluster=~filename)
ggplot(summary_data_st, aes(x=date, y=acquitted, group=crime_st, color=crime_st))+
geom_line()+geom_vline(xintercept=c(1973))
ggplot(summary_data_st, aes(x=date, y=articles_by_paper))+
geom_line()
#install.packages('pacman')
pacman::p_load(plm, lmtest, sandwich, tidyverse, tidyr, broom, stargazer,
fixest, this.path, ggplot2,
dplyr, plyr,
texteffect,
stringr, stringi, remotes,
#wordVectors,
estimatr, lubridate,
stm, tm, quanteda, stringi)
#sets working directory to current folder
setwd(dirname(this.path()))
if(Sys.info()['user']=='fionashenbayh'){pathData<-"/Users/fionashenbayh/Dropbox/Spain_TOP_2022/"}
setwd(pathData)
#ggplot theme
theme_set(theme_classic())
##load cleaned data
top_data<-read.csv('data/cleaned_top_data.csv', stringsAsFactors = F, na.strings = c("NA", '', '[]'))
top_data$trialDate<-as.Date(format(as.Date(top_data$trialDate, '%m/%d/%y'), "19%y-%m-%d"), '%Y-%m-%d')
top_data$p_starting_date<-as.Date(format(as.Date(top_data$p_starting_date, '%m/%d/%y'),"19%y-%m-%d"), '%Y-%m-%d')
news_data<-read.csv('data/abc_coding.csv', stringsAsFactors = F, na.strings = c("NA", '', '[]'))
news_data$trialDate<-NULL
news_data$case_abc<-as.numeric(as.character(news_data$case_abc))
news_data$sentence_confirmed<-as.numeric(as.character(news_data$sentence_confirmed))
news_data[is.na(news_data)]<-0
ot_abc<-read.csv('data/abc_coding.csv')
head(ot_abc)
ot_abc<-read.csv('data/abc_tribunalPublic_order_mentions.csv')
head(ot_abc)
ot_abc$date<-as.Date(paste(ot_abc$year, ot_abc$month, '01' sep='-'))
ot_abc$date<-as.Date(paste(ot_abc$year, ot_abc$month, '01', sep='-'))
ot_abc$date
ggplot(ot_abc, aes(x=date, y=mentions))+
geom_line()
ot_abc_yr<-ddply(ot_abc, .(year), summarize, mentions=sum(mentions))
ot_abc_yr
ggplot(ot_abc_yr, aes(x=year, y=mentions))+
geom_line()
ot_abc<-read.csv('data/abc_military_tribunals.csv')
ot_abc$date<-as.Date(paste(ot_abc$year, ot_abc$month, '01', sep='-'))
ot_abc_yr<-ddply(ot_abc, .(year), summarize, mentions=sum(mentions))
ot_abc_yr<-ddply(ot_abc, .(year), summarize, mentions=sum(mentions))
ggplot(ot_abc, aes(x=year, y=mentions))+
geom_line()
ot_abc$date<-as.Date(paste(ot_abc$year, ot_abc$month, '01', sep='-'))
ggplot(ot_abc, aes(x=date, y=mentions))+
geom_line()
ggplot(ot_abc_yr, aes(x=year, y=mentions))+
geom_line()
ggplot(ot_abc, aes(x=date, y=mentions))+
geom_line()
ot_abc_yr
ot_abc
ot_abc<-read.csv('data/abc_tribunalPublic_order_mentions.csv')
head(ot_abc)
ot_abc$date<-as.Date(paste(ot_abc$year, ot_abc$month, '01', sep='-'))
ot_abc_yr<-ddply(ot_abc, .(year), summarize, mentions=sum(mentions))
ggplot(ot_abc_yr, aes(x=year, y=mentions))+
geom_line()
file_names <- list.files("/Users/jesberg/Dropbox/newspapers_es_ar/abc_es")
file_names
file_names2<-str_split(file_names, '-')
head(file_names2)
file_names2<-str_split(file_names, '-')[[3]]
file_names2
file_names2<-str_split(file_names, '-')
file_names2<-sapply(str_split(file_names, '-'), '[[', 3)
file_names2
file_names <- list.files("/Users/jesberg/Dropbox/newspapers_es_ar/abc_es")
file_names<-sapply(str_split(file_names, '-'), '[[', 3)
file_names
file_names<-as.Date(file_names, '%Y%M%D')
head(file_names)
file_names <- list.files("/Users/jesberg/Dropbox/newspapers_es_ar/abc_es")
file_names<-sapply(str_split(file_names, '-'), '[[', 3)
file_names<-ymd(file_names)
head(file_names)
file_years<-year(file_names)
file_years
head(file_years)
file_years<-data.frame(year(file_names))
head(file_years)
xx<-ddply(file_years, .(year.file_names.), summarize, num=length(year.file_names.))
xx
ggplot(xx, aes(x=year.file_names., y=num))+geom_line()
file_names <- list.files("/Users/jesberg/Dropbox/newspapers_es_ar/abc_es")
head(file_names)
file_names<-unique(ymd(file_names))
file_names <- list.files("/Users/jesberg/Dropbox/newspapers_es_ar/abc_es")
file_names<-sapply(str_split(file_names, '-'), '[[', 3)
file_names<-unique(ymd(file_names))
file_years<-data.frame(year(file_names))
xx<-ddply(file_years, .(year.file_names.), summarize, num=length(year.file_names.))
ggplot(xx, aes(x=year.file_names., y=num))+geom_line()
library(extrafont)
library(magrittr)
library(plyr)
library(rgdal)
#install.packages('extrafontdb')
#system.file("fontmap", "fonttable.csv", package="extrafontdb")
#font_import(paths = NULL, recursive = TRUE, prompt = TRUE,pattern = NULL)
loadfonts()
library(ggplot2)
library(stargazer)
###Replicating stata robust cluster standard errors (Jens Hainmueller code)
require(sandwich)
require(lmtest)
library(RColorBrewer)
library(plm)
vcovCluster <- function(model,
cluster
)
{
require(sandwich)
require(lmtest)
if(nrow(model.matrix(model))!=length(cluster)){
stop("check your data: cluster variable has different N than model")
}
M <- length(unique(cluster))
N <- length(cluster)
K <- model$rank
if(M<50){
warning("Fewer than 50 clusters, variances may be unreliable (could try block bootstrap instead).")
}
dfc <- (M/(M - 1)) * ((N - 1)/(N - K))
uj  <- apply(estfun(model), 2, function(x) tapply(x, cluster, sum));
rcse.cov <- dfc * sandwich(model, meat = crossprod(uj)/N)
return(rcse.cov)
}
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
require(grid)
plots <- c(list(...), plotlist)
numPlots = length(plots)
if (is.null(layout)) {
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
ncol = cols, nrow = ceiling(numPlots/cols))
}
if (numPlots==1) {
print(plots[[1]])
} else {
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))
for (i in 1:numPlots) {
matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))
print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
layout.pos.col = matchidx$col))
}
}
}
setwd("/Users/janeesberg/Desktop/PhD/truthandrec/Audiences_PaperDraft_March2018")
cov<-read.csv("/Users/janeesberg/Desktop/PhD/truthandrec/data/covariates_summer2016.csv")
##Loading all datasets
setwd(dirname(this.path()))
cov<-read.csv("/Users/janeesberg/Desktop/PhD/truthandrec/data/covariates_summer2016.csv")
cov<-read.csv("data/covariates_summer2016.csv")
v4<-read.csv("data/completed_coding_2016.csv")
prefectures<-read.csv("data/Denuncias/prefecturas.csv")
tips<-read.csv("data/Denuncias/denuncias_prefectures.csv")
head)tips
head(tips)
xx<-ddply(tips, .(year), summarize, num=sum(controldearmas))
ggplot(xx, aes(x=year, y=num))+geom_line()
xx<-ddply(tips, .(year), summarize, num=sum(seguridaddelestado))
ggplot(xx, aes(x=year, y=num))+geom_line()
ggplot(tips, aes(x=year, y=seguridaddelestado, color=prefecture, group=prefecture))+geom_line()
ggplot(subset(tips, prefecture%in%tips$prefecture[tips$seguridaddelestado>20], aes(x=year, y=seguridaddelestado, color=prefecture, group=prefecture))+geom_line()
ggplot(subset(tips, prefecture%in%tips$prefecture[tips$seguridaddelestado>20]), aes(x=year, y=seguridaddelestado, color=prefecture, group=prefecture))+geom_line()
ggplot(subset(tips, prefecture%in%tips$prefecture[tips$seguridaddelestado>20]), aes(x=year, y=seguridaddelestado, color=prefecture, group=prefecture))+geom_line()
pacman::p_load(lmtest, plm, ggplot2, tidyr, broom, stargazer,
fixest, this.path, bacondecomp, did, stringr,
stringi, plyr, dplyr, DIDmultiplegt, gridExtra,
extrafont, sf, RColorBrewer)
#sets working directory to current folder
setwd(dirname(this.path()))
